package com.suyx.job.utils;

import java.io.BufferedReader;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

/**
 *
 * <p>Http 工具类</p>
 * @author suyx
 */
public class HttpKit {

    private static HttpDelegate delegate = new DefaultHttpKit();

    public static HttpDelegate getDelegate() {
        return delegate;
    }

    public static void setDelegate(HttpDelegate delegate) {
        HttpKit.delegate = delegate;
    }
    
    public static String readData(HttpServletRequest request) {
		BufferedReader br = null;
		try {
			StringBuilder ret;
			br = request.getReader();
			
			String line = br.readLine();
			if (line != null) {
				ret = new StringBuilder();
				ret.append(line);
			} else {
				return "";
			}
			
			while ((line = br.readLine()) != null) {
				ret.append('\n').append(line);
			}
			
			return ret.toString();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	
}

/**
 * 使用 hutool 实现的 Http 工具类
 *
 * @author Javen
 */
class DefaultHttpKit extends HttpDelegate {
}
